package com.zzj.ecology.system.dto;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName R
 * @Description TODO
 * @Author zhijun zeng at 12:24 2020/5/30
 * @Version 1.0
 **/
public class R implements Serializable {

    public static final int OK_CODE = 200;//HttpStatus.SC_OK
    public static final int NG_CODE = 100;//NO GOOD

    public static final String CAPTCHA = "captcha";
    public static final String DATA_TAG = "data";
    public static final String PAGE_TAG = "page";
    public static final String LIST_TAG = "list";
    public static final String PAR_LIST_TAG = "parlist";//主LIST
    public static final String SUB_LIST_TAG = "sublist";//辅LIST

    private int code;//异常代码
    private String msg;//异常信息
    private Object data;//主要数据
    private Map<String, Object> extend = new HashMap<>();//扩展数据

    public static R ng() {//no good
        return ng("error");
    }

    public static R ng(String ngMsg) {
        return new R(NG_CODE, ngMsg);
    }

    public static R ok() {
        return ok("success");
    }

    public static R ok(String okMsg) {
        return new R(OK_CODE, okMsg);
    }

    public R data(String k, Object v) {
        this.getExtend().put(k , v);
        return this;
    }

    public R(int code , String msg) {
        this.code = code;
        this.msg = msg;
    }

    public R() { }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public R setData(Object data) {
        this.data = data;
        return this;
    }

    public Map<String, Object> getExtend() {
        return extend;
    }

    public void setExtend(Map<String, Object> extend) {
        this.extend = extend;
    }
}
